<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">信息列表</p>
    </div>
    <div class="view-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="搜索" prop="searchValue">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="请输入名称、电话搜索"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status" >
          <el-select
            v-model="queryParams.status"
            placeholder="全部"
            clearable
            size="small"
            style="width:100px;"
          >
            <el-option
              v-for="item in status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="意向" prop="intention" >
          <el-select
            v-model="queryParams.intention"
            placeholder="全部"
            clearable
            size="small"
            style="width:100px;"
          >
            <el-option
              v-for="item in intention"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" class="list-search btn-success" color="#5ED4D4">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" class="list-search">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="list" border>
        <el-table-column label="序号" type="index" align="center" width="50">
          <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人姓名"  align="center" prop="contactName" width="150" />
        <el-table-column label="联系人电话"  align="center" prop="contactPhone" width="150" />
        <el-table-column label="状态"  align="center" prop="status" width="200">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              active-color="#28C6C6"
              inactive-color="#606266"
              active-value="1"
              active-text="已联系"
              inactive-value="0"
              inactive-text="未联系"
              @change="val => onStatus(val, scope.row)"
            >
            </el-switch>
            <!-- <div v-if="scope.row.status == 0">未联系</div> -->
            <!-- <div v-if="scope.row.status == 1">已联系</div> -->
          </template>
        </el-table-column>
        <el-table-column label="意向"  align="center" prop="intention" width="200">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.intention"
              active-color="#28C6C6"
              inactive-color="#ff4949"
              active-value="1"
              active-text="有意向"
              inactive-value="0"
              inactive-text="无意向"
              @change="val => onIntention(val, scope.row)"
            >
            </el-switch>
            <!-- <div v-if="scope.row.intention == 0">无意向</div> -->
            <!-- <div v-if="scope.row.intention == 1">有意向</div> -->
            <!-- <div v-if="scope.row.intention == null || scope.row.intention == ''"></div> -->
          </template>
        </el-table-column>
        <el-table-column label="内容"  align="center" prop="content" />
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { list, edit } from "@/api/system/website/website"
export default {
  name: "list",
  data() {
    return {
      loading: true,
      total: 0,
      list: [],
      status:[
        {
          value:'0',
          label:'未联系'
        },
        {
          value:'1',
          label:'已联系'
        }
      ],
      intention:[
        {
          value:'0',
          label:'无意向'
        },
        {
          value:'1',
          label:'有意向'
        }
      ],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: undefined,
        status: undefined,
        intention:undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      list(this.addDateRange(this.queryParams)).then(res => {
          this.list = res.rows
          this.total = res.total
          this.loading = false
        }
      )
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    onStatus(val, row){
      edit({id: row.id, status: val}).then(res => {
        this.$modal.msgSuccess("操作成功")
      })
    },
    onIntention(val, row){
      edit({id: row.id, intention: val}).then(res => {
        this.$modal.msgSuccess("操作成功")
      })
    },
  }
}
</script>
<style scoped>
::v-deep .el-switch__label.is-active{
  color:#28C6C6;
}
</style>